/*
 * SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 *
 * SPDX-License-Identifier: MulanPSL-2.0
 */
#![allow(
    dead_code,
    mutable_transmutes,
    non_camel_case_types,
    non_snake_case,
    non_upper_case_globals,
    unused_assignments,
    unused_mut,
    unused_variables,
    clippy::never_loop,
    clippy::not_unsafe_ptr_arg_deref
)]

//constants
pub const EXIT_FAILURE: libc::c_int = 1;
pub const LC_ALL: libc::c_int = 6;
pub const RUNAS_GROUP_SPECIFIED: libc::c_int = 2;
pub const RUNAS_USER_SPECIFIED: libc::c_int = 1;
pub const SUDOERS_LOVALE_SUDOERS: libc::c_int = 1;
pub const ENOMEM: libc::c_int = 12;
pub const SUDO_PATH_SECURE: libc::c_int = 0;
pub const SUDO_PATH_MISSING: libc::c_int = -1;
pub const SUDO_PATH_BAD_TYPE: libc::c_int = -2;
pub const SUDO_PATH_WRONG_OWNER: libc::c_int = -3;
pub const SUDO_PATH_WORLD_WRITABLE: libc::c_int = -4;
pub const SUDO_PATH_GROUP_WRITABLE: libc::c_int = -5;
pub const kernel: def_tuple = 9;
pub const tty: def_tuple = 8;
pub const ppid: def_tuple = 7;
pub const global: def_tuple = 6;
pub const digest_only: def_tuple = 5;
pub const all: def_tuple = 4;
pub const any: def_tuple = 3;
pub const always: def_tuple = 2;
pub const once: def_tuple = 1;
pub const never: def_tuple = 0;
pub const format_sudoers: sudoers_formats = 1;
pub const format_ldif: sudoers_formats = 0;

#[macro_use]
mod common;
use crate::common::alias as alias_struct;
use crate::common::defaults as defaults_struct;
use crate::common::*;

mod alias;
mod audit;
mod base64;
mod defaults;
mod digestname;
mod editor;
mod filedigest;
mod find_path;
mod fmtsudoers;
mod gentime;
mod gmtoff;
mod goodpath;
mod gram;
mod group_plugin;
mod hexchar;
mod interfaces;
mod ldap_util;
mod linux_audit;
mod locale;
// mod net_ifs;
mod logging;
mod logwrap;
mod r#match;
mod match_addr;
mod match_command;
mod match_digest;
mod parse_ldif;
mod pwutil;
mod pwutil_impl;
mod rcstr;
mod redblack;
mod strlist;
mod sudo_printf;
mod sudoers_debug;
mod timeout;
mod timestr;
mod toke;
mod toke_util;
mod tsgetgrpw;

#[link(name = "audit")]
#[link(name = "utsudo_util")]
#[link(name = "util_variadic")]
#[link(name = "plugins_variadic")]
#[link(name = "utsudo_noexec")]
extern "C" {
    static mut stdin: *mut FILE;
    static mut stdout: *mut FILE;
    static mut stderr: *mut FILE;
    fn fopen(_: *const libc::c_char, _: *const libc::c_char) -> *mut FILE;
    fn fprintf(_: *mut FILE, _: *const libc::c_char, _: ...) -> libc::c_int;
    fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
    fn putc(__c: libc::c_int, __stream: *mut FILE) -> libc::c_int;
    fn fputs(__s: *const libc::c_char, __stream: *mut FILE) -> libc::c_int;
    fn puts(__s: *const libc::c_char) -> libc::c_int;
    fn malloc(_: libc::c_ulong) -> *mut libc::c_void;
    fn exit(_: libc::c_int) -> !;
    fn strdup(_: *const libc::c_char) -> *mut libc::c_char;
    fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
    fn strrchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
    fn strlen(_: *const libc::c_char) -> libc::c_ulong;
    fn strcasecmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int;
    static mut optarg: *mut libc::c_char;
    static mut optind: libc::c_int;
    fn getopt(
        ___argc: libc::c_int,
        ___argv: *const *mut libc::c_char,
        __shortopts: *const libc::c_char,
    ) -> libc::c_int;
    fn __errno_location() -> *mut libc::c_int;
    fn setgrfile(_: *const libc::c_char);
    fn setpwfile(_: *const libc::c_char);
    fn alias_type_to_string(alias_type: libc::c_int) -> *const libc::c_char;
    fn alias_apply(
        parse_tree: *mut sudoers_parse_tree,
        func: Option<
            unsafe extern "C" fn(
                *mut sudoers_parse_tree,
                *mut alias_struct,
                *mut libc::c_void,
            ) -> libc::c_int,
        >,
        cookie: *mut libc::c_void,
    );
    static mut parsed_policy: sudoers_parse_tree;
    fn init_parser(path: *const libc::c_char, quiet: bool) -> bool;
    fn textdomain(__domainname: *const libc::c_char) -> *mut libc::c_char;
    fn bindtextdomain(
        __domainname: *const libc::c_char,
        __dirname: *const libc::c_char,
    ) -> *mut libc::c_char;
    fn sudo_strlcpy(dst: *mut libc::c_char, src: *const libc::c_char, siz: size_t) -> size_t;
    fn sudo_getprogname() -> *const libc::c_char;
    fn sudo_warn_gettext_v1(
        domainname: *const libc::c_char,
        msgid: *const libc::c_char,
    ) -> *mut libc::c_char;
    fn sudo_warn_set_locale_func_v1(
        func: Option<unsafe extern "C" fn(bool, *mut libc::c_int) -> bool>,
    );
    fn sudo_fatal_nodebug_v1(fmt: *const libc::c_char, _: ...) -> !;
    fn sudo_fatalx_nodebug_v1(fmt: *const libc::c_char, _: ...) -> !;
    fn sudo_warn_nodebug_v1(fmt: *const libc::c_char, _: ...);
    fn sudo_warnx_nodebug_v1(fmt: *const libc::c_char, _: ...);
    fn init_defaults() -> bool;
    fn update_defaults(
        parse_tree: *mut sudoers_parse_tree,
        defs: *mut defaults_list,
        what: libc::c_int,
        quiet: bool,
    ) -> bool;
    static mut sudo_defs_table: [sudo_defs_types; 0];
    fn sudoers_warn_setlocale(restore: bool, cookie: *mut libc::c_int) -> bool;
    fn sudoers_setlocale(newlocale: libc::c_int, prevlocale: *mut libc::c_int) -> bool;
    fn sudoers_initlocale(ulocale: *const libc::c_char, slocale: *const libc::c_char) -> bool;
    fn sudoers_locale_callback(_: *const sudo_defs_val) -> bool;
    fn cmnd_matches(parse_tree: *mut sudoers_parse_tree, m: *const member) -> libc::c_int;
    fn hostlist_matches(
        parse_tree: *mut sudoers_parse_tree,
        pw: *const passwd,
        list: *const member_list,
    ) -> libc::c_int;
    fn runaslist_matches(
        parse_tree: *mut sudoers_parse_tree,
        user_list: *const member_list,
        group_list: *const member_list,
        matching_user: *mut *mut member,
        matching_group: *mut *mut member,
    ) -> libc::c_int;
    fn userlist_matches(
        parse_tree: *mut sudoers_parse_tree,
        pw: *const passwd,
        list: *const member_list,
    ) -> libc::c_int;
    fn sudoers_parse_ldif(
        parse_tree: *mut sudoers_parse_tree,
        fp: *mut FILE,
        sudoers_base: *const libc::c_char,
        store_options: bool,
    ) -> bool;
    fn sudoers_format_default_line(
        lbuf: *mut sudo_lbuf,
        parse_tree: *mut sudoers_parse_tree,
        d: *mut defaults_struct,
        next: *mut *mut defaults_struct,
        expand_aliases: bool,
    ) -> bool;
    fn sudoers_format_member(
        lbuf: *mut sudo_lbuf,
        parse_tree: *mut sudoers_parse_tree,
        m: *mut member,
        separator: *const libc::c_char,
        alias_type: libc::c_int,
    ) -> bool;
    fn sudoers_format_privilege(
        lbuf: *mut sudo_lbuf,
        parse_tree: *mut sudoers_parse_tree,
        priv_0: *mut privilege,
        expand_aliases: bool,
    ) -> bool;
    fn sudoers_format_userspecs(
        lbuf: *mut sudo_lbuf,
        parse_tree: *mut sudoers_parse_tree,
        separator: *const libc::c_char,
        expand_aliases: bool,
        flush: bool,
    ) -> bool;
    fn sudo_conf_read_v1(conf_file: *const libc::c_char, conf_types: libc::c_int) -> libc::c_int;
    fn sudo_conf_debug_files_v1(progname: *const libc::c_char) -> *mut sudo_conf_debug_file_list;
    fn sudo_gethostname_v1() -> *mut libc::c_char;
    fn initprogname(_: *const libc::c_char);
    fn sudo_secure_file_v1(
        path: *const libc::c_char,
        uid: uid_t,
        gid: gid_t,
        sbp: *mut stat,
    ) -> libc::c_int;
    fn sudo_strtoid_v2(str: *const libc::c_char, errstr: *mut *const libc::c_char) -> id_t;
    fn sudo_debug_enter_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
    );
    fn sudo_debug_exit_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
    );
    fn sudo_debug_exit_bool_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: bool,
    );
    fn sudo_debug_exit_int_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: libc::c_int,
    );
    fn sudo_debug_exit_ptr_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: *const libc::c_void,
    );
    fn sudo_debug_printf2_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        level: libc::c_int,
        fmt: *const libc::c_char,
        _: ...
    );
    static mut sudoers_subsystem_ids: [libc::c_uint; 0];
    fn setlocale(__category: libc::c_int, __locale: *const libc::c_char) -> *mut libc::c_char;
    fn sudoersparse() -> libc::c_int;
    static mut errorfile: *mut libc::c_char;
    static mut errorlineno: libc::c_int;
    static mut parse_error: bool;
    static mut sudoers_uid: uid_t;
    static mut sudoers_gid: gid_t;
    fn sudo_freepwcache();
    fn sudo_freegrcache();
    fn sudo_getpwuid(_: uid_t) -> *mut passwd;
    fn sudo_getgrgid(_: gid_t) -> *mut group;
    fn sudo_getgrnam(_: *const libc::c_char) -> *mut group;
    fn sudo_gr_delref(_: *mut group);
    fn sudo_fakegrnam(_: *const libc::c_char) -> *mut group;
    fn sudo_fakepwnam(_: *const libc::c_char, _: gid_t) -> *mut passwd;
    fn sudo_getpwnam(_: *const libc::c_char) -> *mut passwd;
    fn sudo_pw_delref(_: *mut passwd);
    fn cb_group_plugin(sd_un: *const sudo_defs_val) -> bool;
    fn sudoers_debug_register(
        plugin_path: *const libc::c_char,
        debug_files: *mut sudo_conf_debug_file_list,
    ) -> bool;
    fn get_net_ifs(addrinfo: *mut *mut libc::c_char) -> libc::c_int;
    fn set_interfaces(_: *const libc::c_char) -> bool;
    fn sudo_lbuf_init_v1(
        lbuf: *mut sudo_lbuf,
        output: sudo_lbuf_output_t,
        indent: libc::c_int,
        continuation: *const libc::c_char,
        cols: libc::c_int,
    );
    fn sudo_lbuf_destroy_v1(lbuf: *mut sudo_lbuf);
    fn sudo_lbuf_append_v1(lbuf: *mut sudo_lbuf, fmt: *const libc::c_char, _: ...) -> bool;
    fn sudo_lbuf_print_v1(lbuf: *mut sudo_lbuf);
    fn sudo_lbuf_error_v1(lbuf: *mut sudo_lbuf) -> bool;
    static mut trace_print: Option<unsafe extern "C" fn(*const libc::c_char) -> libc::c_int>;
}

pub type __dev_t = libc::c_ulong;
pub type __uid_t = libc::c_uint;
pub type __gid_t = libc::c_uint;
pub type __ino_t = libc::c_ulong;
pub type __mode_t = libc::c_uint;
pub type __off_t = libc::c_long;
pub type __off64_t = libc::c_long;
pub type __pid_t = libc::c_int;
pub type __id_t = libc::c_uint;
pub type __time_t = libc::c_long;
pub type __blkcnt_t = libc::c_long;
pub type __syscall_slong_t = libc::c_long;
pub type gid_t = __gid_t;
pub type mode_t = __mode_t;
pub type uid_t = __uid_t;
pub type pid_t = __pid_t;
pub type id_t = __id_t;
pub type time_t = __time_t;
pub type size_t = libc::c_ulong;
pub type _IO_lock_t = ();
pub type FILE = _IO_FILE;
pub type def_tuple = libc::c_uint;
pub type sudo_lbuf_output_t = Option<unsafe extern "C" fn(*const libc::c_char) -> libc::c_int>;
pub type sudoers_formats = libc::c_uint;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct _IO_FILE {
    pub _flags: libc::c_int,
    pub _IO_read_ptr: *mut libc::c_char,
    pub _IO_read_end: *mut libc::c_char,
    pub _IO_read_base: *mut libc::c_char,
    pub _IO_write_base: *mut libc::c_char,
    pub _IO_write_ptr: *mut libc::c_char,
    pub _IO_write_end: *mut libc::c_char,
    pub _IO_buf_base: *mut libc::c_char,
    pub _IO_buf_end: *mut libc::c_char,
    pub _IO_save_base: *mut libc::c_char,
    pub _IO_backup_base: *mut libc::c_char,
    pub _IO_save_end: *mut libc::c_char,
    pub _markers: *mut _IO_marker,
    pub _chain: *mut _IO_FILE,
    pub _fileno: libc::c_int,
    pub _flags2: libc::c_int,
    pub _old_offset: __off_t,
    pub _cur_column: libc::c_ushort,
    pub _vtable_offset: libc::c_schar,
    pub _shortbuf: [libc::c_char; 1],
    pub _lock: *mut libc::c_void,
    pub _offset: __off64_t,
    pub _codecvt: *mut _IO_codecvt,
    pub _wide_data: *mut _IO_wide_data,
    pub _freeres_list: *mut _IO_FILE,
    pub _freeres_buf: *mut libc::c_void,
    pub __pad5: size_t,
    pub _mode: libc::c_int,
    pub _unused2: [libc::c_char; 20],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct passwd {
    pub pw_name: *mut libc::c_char,
    pub pw_passwd: *mut libc::c_char,
    pub pw_uid: __uid_t,
    pub pw_gid: __gid_t,
    pub pw_gecos: *mut libc::c_char,
    pub pw_dir: *mut libc::c_char,
    pub pw_shell: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct group {
    pub gr_name: *mut libc::c_char,
    pub gr_passwd: *mut libc::c_char,
    pub gr_gid: __gid_t,
    pub gr_mem: *mut *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct list_member {
    pub entries: C2RustUnnamed,
    pub value: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed {
    pub sle_next: *mut list_member,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct list_members {
    pub slh_first: *mut list_member,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct def_values {
    pub sval: *mut libc::c_char,
    pub nval: def_tuple,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub union sudo_defs_val {
    pub flag: libc::c_int,
    pub ival: libc::c_int,
    pub uival: libc::c_uint,
    pub tuple: def_tuple,
    pub str_0: *mut libc::c_char,
    pub mode: mode_t,
    pub tspec: timespec,
    pub list: list_members,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_defs_types {
    pub name: *mut libc::c_char,
    pub type_0: libc::c_int,
    pub desc: *mut libc::c_char,
    pub values: *mut def_values,
    pub callback: Option<unsafe extern "C" fn(*const sudo_defs_val) -> bool>,
    pub sd_un: sudo_defs_val,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct defaults_list {
    pub tqh_first: *mut defaults_struct,
    pub tqh_last: *mut *mut defaults_struct,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct member_list {
    pub tqh_first: *mut member,
    pub tqh_last: *mut *mut member,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub tqe_next: *mut member,
    pub tqe_prev: *mut *mut member,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub tqe_next: *mut defaults_struct,
    pub tqe_prev: *mut *mut defaults_struct,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudoers_parse_tree {
    pub userspecs: userspec_list,
    pub defaults: defaults_list,
    pub aliases: *mut rbtree,
    pub shost: *const libc::c_char,
    pub lhost: *const libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct userspec_list {
    pub tqh_first: *mut userspec,
    pub tqh_last: *mut *mut userspec,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct userspec {
    pub entries: C2RustUnnamed_5,
    pub users: member_list,
    pub privileges: privilege_list,
    pub comments: comment_list,
    pub lineno: libc::c_int,
    pub file: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct comment_list {
    pub stqh_first: *mut sudoers_comment,
    pub stqh_last: *mut *mut sudoers_comment,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudoers_comment {
    pub entries: C2RustUnnamed_2,
    pub str_0: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
    pub stqe_next: *mut sudoers_comment,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct privilege_list {
    pub tqh_first: *mut privilege,
    pub tqh_last: *mut *mut privilege,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct privilege {
    pub entries: C2RustUnnamed_4,
    pub ldap_role: *mut libc::c_char,
    pub hostlist: member_list,
    pub cmndlist: cmndspec_list,
    pub defaults: defaults_list,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmndspec_list {
    pub tqh_first: *mut cmndspec,
    pub tqh_last: *mut *mut cmndspec,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmndspec {
    pub entries: C2RustUnnamed_3,
    pub runasuserlist: *mut member_list,
    pub runasgrouplist: *mut member_list,
    pub cmnd: *mut member,
    pub tags: cmndtag,
    pub timeout: libc::c_int,
    pub notbefore: time_t,
    pub notafter: time_t,
    pub role: *mut libc::c_char,
    pub type_0: *mut libc::c_char,
}

#[derive(Copy, Clone, BitfieldStruct)]
#[repr(C)]
pub struct cmndtag {
    #[bitfield(name = "nopasswd", ty = "libc::c_int", bits = "0..=2")]
    #[bitfield(name = "noexec", ty = "libc::c_int", bits = "3..=5")]
    #[bitfield(name = "setenv", ty = "libc::c_int", bits = "6..=8")]
    #[bitfield(name = "log_input", ty = "libc::c_int", bits = "9..=11")]
    #[bitfield(name = "log_output", ty = "libc::c_int", bits = "12..=14")]
    #[bitfield(name = "send_mail", ty = "libc::c_int", bits = "15..=17")]
    #[bitfield(name = "follow", ty = "libc::c_int", bits = "18..=20")]
    pub nopasswd_noexec_setenv_log_input_log_output_send_mail_follow: [u8; 3],
    #[bitfield(padding)]
    pub c2rust_padding: [u8; 1],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_3 {
    pub tqe_next: *mut cmndspec,
    pub tqe_prev: *mut *mut cmndspec,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_4 {
    pub tqe_next: *mut privilege,
    pub tqe_prev: *mut *mut privilege,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_5 {
    pub tqe_next: *mut userspec,
    pub tqe_prev: *mut *mut userspec,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct gid_list {
    pub ngids: libc::c_int,
    pub gids: *mut gid_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_lbuf {
    pub output: Option<unsafe extern "C" fn(*const libc::c_char) -> libc::c_int>,
    pub buf: *mut libc::c_char,
    pub continuation: *const libc::c_char,
    pub indent: libc::c_int,
    pub len: libc::c_int,
    pub size: libc::c_int,
    pub cols: libc::c_short,
    pub error: libc::c_short,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_debug_file {
    pub entries: C2RustUnnamed_6,
    pub debug_file: *mut libc::c_char,
    pub debug_flags: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_6 {
    pub tqe_next: *mut sudo_debug_file,
    pub tqe_prev: *mut *mut sudo_debug_file,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_conf_debug_file_list {
    pub tqh_first: *mut sudo_debug_file,
    pub tqh_last: *mut *mut sudo_debug_file,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_user {
    pub pw: *mut passwd,
    pub _runas_pw: *mut passwd,
    pub _runas_gr: *mut group,
    pub cmnd_stat: *mut stat,
    pub name: *mut libc::c_char,
    pub path: *mut libc::c_char,
    pub tty: *mut libc::c_char,
    pub ttypath: *mut libc::c_char,
    pub host: *mut libc::c_char,
    pub shost: *mut libc::c_char,
    pub runhost: *mut libc::c_char,
    pub srunhost: *mut libc::c_char,
    pub prompt: *mut libc::c_char,
    pub cmnd: *mut libc::c_char,
    pub cmnd_args: *mut libc::c_char,
    pub cmnd_base: *mut libc::c_char,
    pub cmnd_safe: *mut libc::c_char,
    pub class_name: *mut libc::c_char,
    pub krb5_ccname: *mut libc::c_char,
    pub gid_list: *mut gid_list,
    pub env_vars: *const *mut libc::c_char,
    pub role: *mut libc::c_char,
    pub type_0: *mut libc::c_char,
    pub cwd: *const libc::c_char,
    pub iolog_file: *mut libc::c_char,
    pub gids: *mut gid_t,
    pub execfd: libc::c_int,
    pub ngids: libc::c_int,
    pub closefrom: libc::c_int,
    pub lines: libc::c_int,
    pub cols: libc::c_int,
    pub flags: libc::c_int,
    pub max_groups: libc::c_int,
    pub timeout: libc::c_int,
    pub umask: mode_t,
    pub uid: uid_t,
    pub gid: uid_t,
    pub sid: pid_t,
}

#[inline]
unsafe extern "C" fn putchar(mut __c: libc::c_int) -> libc::c_int {
    putc(__c, stdout)
}

#[no_mangle]
pub static mut sudo_user: sudo_user = sudo_user {
    pw: 0 as *const passwd as *mut passwd,
    _runas_pw: 0 as *const passwd as *mut passwd,
    _runas_gr: 0 as *const group as *mut group,
    cmnd_stat: 0 as *const stat as *mut stat,
    name: 0 as *const libc::c_char as *mut libc::c_char,
    path: 0 as *const libc::c_char as *mut libc::c_char,
    tty: 0 as *const libc::c_char as *mut libc::c_char,
    ttypath: 0 as *const libc::c_char as *mut libc::c_char,
    host: 0 as *const libc::c_char as *mut libc::c_char,
    shost: 0 as *const libc::c_char as *mut libc::c_char,
    runhost: 0 as *const libc::c_char as *mut libc::c_char,
    srunhost: 0 as *const libc::c_char as *mut libc::c_char,
    prompt: 0 as *const libc::c_char as *mut libc::c_char,
    cmnd: 0 as *const libc::c_char as *mut libc::c_char,
    cmnd_args: 0 as *const libc::c_char as *mut libc::c_char,
    cmnd_base: 0 as *const libc::c_char as *mut libc::c_char,
    cmnd_safe: 0 as *const libc::c_char as *mut libc::c_char,
    class_name: 0 as *const libc::c_char as *mut libc::c_char,
    krb5_ccname: 0 as *const libc::c_char as *mut libc::c_char,
    gid_list: 0 as *const gid_list as *mut gid_list,
    env_vars: 0 as *const *mut libc::c_char,
    role: 0 as *const libc::c_char as *mut libc::c_char,
    type_0: 0 as *const libc::c_char as *mut libc::c_char,
    cwd: 0 as *const libc::c_char,
    iolog_file: 0 as *const libc::c_char as *mut libc::c_char,
    gids: 0 as *const gid_t as *mut gid_t,
    execfd: 0,
    ngids: 0,
    closefrom: 0,
    lines: 0,
    cols: 0,
    flags: 0,
    max_groups: 0,
    timeout: 0,
    umask: 0,
    uid: 0,
    gid: 0,
    sid: 0,
};

#[no_mangle]
pub static mut list_pw: *mut passwd = 0 as *const passwd as *mut passwd;
static mut runas_group: *mut libc::c_char = 0 as *const libc::c_char as *mut libc::c_char;
static mut runas_user: *mut libc::c_char = 0 as *const libc::c_char as *mut libc::c_char;

#[no_mangle]
fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> libc::c_int {
    let mut input_format: sudoers_formats = format_sudoers;
    let mut cs: *mut cmndspec = std::ptr::null_mut::<cmndspec>();
    let mut priv_0: *mut privilege = std::ptr::null_mut::<privilege>();
    let mut us: *mut userspec = std::ptr::null_mut::<userspec>();
    let mut p: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut grfile: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut pwfile: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut errstr: *const libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut match_0: libc::c_int = 0;
    let mut host_match: libc::c_int = 0;
    let mut runas_match: libc::c_int = 0;
    let mut cmnd_match: libc::c_int = 0;
    let mut ch: libc::c_int = 0;
    let mut dflag: libc::c_int = 0;
    let mut exitcode: libc::c_int = 1 as libc::c_int;
    let mut lbuf: sudo_lbuf = sudo_lbuf {
        output: None,
        buf: std::ptr::null_mut::<libc::c_char>(),
        continuation: std::ptr::null::<libc::c_char>(),
        indent: 0,
        len: 0,
        size: 0,
        cols: 0,
        error: 0,
    };
    unsafe {
        debug_decl!(SUDOERS_DEBUG_MAIN!());
    }

    unsafe {
        initprogname(if argc > 0 as libc::c_int {
            *argv.offset(0 as libc::c_int as isize)
        } else {
            b"testsudoers\0" as *const u8 as *const libc::c_char
        });

        if !sudoers_initlocale(
            setlocale(
                LC_ALL as libc::c_int,
                b"\0" as *const u8 as *const libc::c_char,
            ),
            (*sudo_defs_table
                .as_mut_ptr()
                .offset(69 as libc::c_int as isize))
            .sd_un
            .str_0,
        ) {
            sudo_fatalx!(
                b"%s: %s\0" as *const u8 as *const libc::c_char,
                get_function_name!(),
                b"unable to allocate memory\0" as *const u8 as *const libc::c_char
            );
        }

        sudo_warn_set_locale_func_v1(Some(
            sudoers_warn_setlocale as unsafe extern "C" fn(bool, *mut libc::c_int) -> bool,
        ));

        bindtextdomain(
            b"sudoers\0" as *const u8 as *const libc::c_char,
            b"/usr/share/locale\0" as *const u8 as *const libc::c_char,
        );
        textdomain(b"sudoers\0" as *const u8 as *const libc::c_char);

        sudo_lbuf_init_v1(
            &mut lbuf,
            Some(testsudoers_output as unsafe extern "C" fn(*const libc::c_char) -> libc::c_int),
            0 as libc::c_int,
            std::ptr::null::<libc::c_char>(),
            0 as libc::c_int,
        );

        'done: loop {
            if sudo_conf_read_v1(std::ptr::null::<libc::c_char>(), 0x1 as libc::c_int)
                == -(1 as libc::c_int)
            {
                break 'done;
            }

            if !sudoers_debug_register(
                sudo_getprogname(),
                sudo_conf_debug_files_v1(sudo_getprogname()),
            ) {
                break 'done;
            }

            dflag = 0 as libc::c_int;
            pwfile = std::ptr::null_mut::<libc::c_char>();
            grfile = pwfile;

            loop {
                ch = getopt(
                    argc,
                    argv as *const *mut libc::c_char,
                    b"dg:G:h:i:P:p:tu:U:\0" as *const u8 as *const libc::c_char,
                );
                if ch == -(1 as libc::c_int) {
                    break;
                }
                match ch as u8 as char {
                    'd' => {
                        dflag = 1;
                    }
                    'G' => {
                        sudoers_gid = sudo_strtoid_v2(optarg, &mut errstr);
                        if !errstr.is_null() {
                            sudo_fatalx!(
                                b"group-ID %s: %s\0" as *const u8 as *const libc::c_char,
                                optarg,
                                errstr
                            );
                        }
                    }
                    'g' => {
                        runas_group = optarg;
                        sudo_user.flags |= RUNAS_GROUP_SPECIFIED as libc::c_int;
                    }
                    'h' => {
                        sudo_user.host = optarg;
                    }
                    'i' => {
                        if strcasecmp(optarg, b"ldif\0" as *const u8 as *const libc::c_char)
                            == 0 as libc::c_int
                        {
                            input_format = format_ldif;
                        } else if strcasecmp(
                            optarg,
                            b"sudoers\0" as *const u8 as *const libc::c_char,
                        ) == 0 as libc::c_int
                        {
                            input_format = format_sudoers;
                        } else {
                            sudo_warnx!(
                                b"unsupported input format %s\0" as *const u8
                                    as *const libc::c_char,
                                optarg
                            );
                            usage();
                        }
                    }
                    'p' => {
                        pwfile = optarg;
                    }
                    'P' => {
                        grfile = optarg;
                    }
                    't' => {
                        trace_print = Some(
                            testsudoers_error
                                as unsafe extern "C" fn(*const libc::c_char) -> libc::c_int,
                        );
                    }
                    'U' => {
                        sudoers_uid = sudo_strtoid_v2(optarg, &mut errstr);
                        if !errstr.is_null() {
                            sudo_fatalx!(
                                b"user-ID %s: %s\0" as *const u8 as *const libc::c_char,
                                optarg,
                                errstr
                            );
                        }
                    }
                    'u' => {
                        runas_user = optarg;
                        sudo_user.flags |= RUNAS_USER_SPECIFIED;
                    }
                    _ => {
                        usage();
                    }
                }
            } //as loop

            argc -= optind;
            argv = argv.offset(optind as isize);

            if !grfile.is_null() {
                setgrfile(grfile);
            }
            if !pwfile.is_null() {
                setpwfile(pwfile);
            }

            if argc < 2 as libc::c_int {
                if dflag == 0 {
                    usage();
                }
                sudo_user.name = (if argc != 0 {
                    let fresh0 = argv;
                    argv = argv.offset(1);
                    *fresh0
                } else {
                    b"root\0" as *const u8 as *const libc::c_char
                }) as *mut libc::c_char;
                sudo_user.cmnd_base =
                    b"true\0" as *const u8 as *const libc::c_char as *mut libc::c_char;
                sudo_user.cmnd = sudo_user.cmnd_base;
                argc = 0 as libc::c_int;
            } else {
                let fresh1 = argv;
                argv = argv.offset(1);
                sudo_user.name = *fresh1;
                let fresh2 = argv;
                argv = argv.offset(1);
                sudo_user.cmnd = *fresh2;
                p = strrchr(sudo_user.cmnd, '/' as i32);
                if !p.is_null() {
                    sudo_user.cmnd_base = p.offset(1 as libc::c_int as isize);
                } else {
                    sudo_user.cmnd_base = sudo_user.cmnd;
                }
                argc -= 2 as libc::c_int;
            }

            sudo_user.pw = sudo_getpwnam(sudo_user.name);
            if (sudo_user.pw).is_null() {
                sudo_fatalx!(
                    b"unknown user: %s\0" as *const u8 as *const libc::c_char,
                    sudo_user.name
                );
            }

            if (sudo_user.host).is_null() {
                sudo_user.host = sudo_gethostname_v1();
                if (sudo_user.host).is_null() {
                    sudo_fatal!(b"gethostname\0" as *const u8 as *const libc::c_char,);
                }
            }

            p = strchr(sudo_user.host, '.' as i32);
            if !p.is_null() {
                *p = '\u{0}' as i32 as libc::c_char;
                sudo_user.shost = strdup(sudo_user.host);
                if (sudo_user.shost).is_null() {
                    sudo_fatalx!(
                        b"%s: %s\0" as *const u8 as *const libc::c_char,
                        get_function_name!(),
                        b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                    );
                }
                *p = '.' as i32 as libc::c_char;
            } else {
                sudo_user.shost = sudo_user.host;
            }
            sudo_user.runhost = sudo_user.host;
            sudo_user.srunhost = sudo_user.shost;

            if argc > 0 as libc::c_int {
                let mut to: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
                let mut from: *mut *mut libc::c_char = std::ptr::null_mut::<*mut libc::c_char>();
                let mut size: size_t = 0;
                let mut n: size_t = 0;
                size = 0 as libc::c_int as size_t;
                from = argv;
                while !(*from).is_null() {
                    size = (size as libc::c_ulong).wrapping_add(
                        (strlen(*from)).wrapping_add(1 as libc::c_int as libc::c_ulong),
                    ) as size_t as size_t;
                    from = from.offset(1);
                }
                sudo_user.cmnd_args = malloc(size) as *mut libc::c_char;
                if (sudo_user.cmnd_args).is_null() {
                    sudo_fatalx!(
                        b"%s: %s\0" as *const u8 as *const libc::c_char,
                        get_function_name!(),
                        b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                    );
                }

                to = sudo_user.cmnd_args;
                from = argv;
                while !(*from).is_null() {
                    n = sudo_strlcpy(
                        to,
                        *from,
                        size.wrapping_sub(
                            to.offset_from(sudo_user.cmnd_args) as libc::c_long as libc::c_ulong
                        ),
                    );
                    if n >= size.wrapping_sub(
                        to.offset_from(sudo_user.cmnd_args) as libc::c_long as libc::c_ulong
                    ) {
                        sudo_fatalx!(
                            b"internal error, %s overflow\0" as *const u8 as *const libc::c_char,
                            sudo_getprogname()
                        );
                    }
                    to = to.offset(n as isize);
                    let fresh3 = to;
                    to = to.offset(1);
                    *fresh3 = ' ' as i32 as libc::c_char;
                    from = from.offset(1);
                }
                to = to.offset(-1);
                *to = '\u{0}' as i32 as libc::c_char;
            } //if argc > 0

            if !init_defaults() {
                sudo_fatalx!(
                    b"unable to initialize sudoers default values\0" as *const u8
                        as *const libc::c_char,
                );
            }

            let fresh4 = &mut (*sudo_defs_table
                .as_mut_ptr()
                .offset(78 as libc::c_int as isize))
            .callback;
            *fresh4 = Some(cb_group_plugin as unsafe extern "C" fn(*const sudo_defs_val) -> bool);

            let fresh5 = &mut (*sudo_defs_table
                .as_mut_ptr()
                .offset(51 as libc::c_int as isize))
            .callback;
            *fresh5 = Some(cb_runas_default as unsafe extern "C" fn(*const sudo_defs_val) -> bool);

            let fresh6 = &mut (*sudo_defs_table
                .as_mut_ptr()
                .offset(69 as libc::c_int as isize))
            .callback;
            *fresh6 =
                Some(sudoers_locale_callback as unsafe extern "C" fn(*const sudo_defs_val) -> bool);

            /*if get_net_ifs(&mut p) > 0 as libc::c_int {
                if !set_interfaces(p) {
                    sudo_fatal!(
                        b"unable to parse network address list\0" as *const u8
                            as *const libc::c_char,
                    );
                }
            }*/
            if get_net_ifs(&mut p) > 0 as libc::c_int && !set_interfaces(p) {
                sudo_fatal!(
                    b"unable to parse network address list\0" as *const u8 as *const libc::c_char,
                );
            }

            init_parser(
                b"sudoers\0" as *const u8 as *const libc::c_char,
                0 as libc::c_int != 0,
            );

            if !runas_group.is_null() {
                set_runasgr(runas_group);
                set_runaspw(if !runas_user.is_null() {
                    runas_user
                } else {
                    sudo_user.name
                });
            } else {
                set_runaspw(if !runas_user.is_null() {
                    runas_user
                } else {
                    (*sudo_defs_table
                        .as_mut_ptr()
                        .offset(51 as libc::c_int as isize))
                    .sd_un
                    .str_0
                });
            }

            sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, std::ptr::null_mut::<libc::c_int>());

            match input_format {
                0 => {
                    if !sudoers_parse_ldif(
                        &mut parsed_policy,
                        stdin,
                        std::ptr::null::<libc::c_char>(),
                        1 as libc::c_int != 0,
                    ) {
                        printf(b"Parse error in LDIF\0" as *const u8 as *const libc::c_char);
                    } else {
                        fputs(b"Parses OK\0" as *const u8 as *const libc::c_char, stdout);
                    }
                }
                1 => {
                    if sudoersparse() != 0 as libc::c_int || parse_error as libc::c_int != 0 {
                        parse_error = 1 as libc::c_int != 0;
                        if errorlineno != -(1 as libc::c_int) {
                            printf(
                                b"Parse error in %s near line %d\0" as *const u8
                                    as *const libc::c_char,
                                errorfile,
                                errorlineno,
                            );
                        } else {
                            printf(
                                b"Parse error in %s\0" as *const u8 as *const libc::c_char,
                                errorfile,
                            );
                        }
                    } else {
                        fputs(b"Parses OK\0" as *const u8 as *const libc::c_char, stdout);
                    }
                }
                _ => {
                    sudo_fatalx!(
                        b"error: unhandled input %d\0" as *const u8 as *const libc::c_char,
                        input_format
                    );
                }
            } //match

            if !update_defaults(
                &mut parsed_policy,
                std::ptr::null_mut::<defaults_list>(),
                0x1 as libc::c_int
                    | 0x2 as libc::c_int
                    | 0x4 as libc::c_int
                    | 0x8 as libc::c_int
                    | 0x10 as libc::c_int,
                0 as libc::c_int != 0,
            ) {
                fputs(
                    b" (problem with defaults entries)\0" as *const u8 as *const libc::c_char,
                    stdout,
                );
            }
            puts(b".\0" as *const u8 as *const libc::c_char);

            if dflag != 0 {
                putchar('\n' as i32);
                dump_sudoers(&mut lbuf);
                if argc < 2 as libc::c_int {
                    exitcode = if parse_error as libc::c_int != 0 {
                        1 as libc::c_int
                    } else {
                        0 as libc::c_int
                    };
                    break 'done;
                }
            }

            printf(
                b"\nEntries for user %s:\n\0" as *const u8 as *const libc::c_char,
                sudo_user.name,
            );
            match_0 = -(1 as libc::c_int);

            us = *(*(parsed_policy.userspecs.tqh_last as *mut userspec_list)).tqh_last;
            while !us.is_null() {
                if userlist_matches(&mut parsed_policy, sudo_user.pw, &(*us).users)
                    != 1 as libc::c_int
                {
                    us = *(*((*us).entries.tqe_prev as *mut userspec_list)).tqh_last;
                    continue;
                }
                priv_0 = *(*((*us).privileges.tqh_last as *mut privilege_list)).tqh_last;
                while !priv_0.is_null() {
                    sudo_lbuf_append_v1(
                        &mut lbuf as *mut sudo_lbuf,
                        b"\n\0" as *const u8 as *const libc::c_char,
                    );
                    sudoers_format_privilege(
                        &mut lbuf,
                        &mut parsed_policy,
                        priv_0,
                        0 as libc::c_int != 0,
                    );
                    sudo_lbuf_print_v1(&mut lbuf);
                    host_match =
                        hostlist_matches(&mut parsed_policy, sudo_user.pw, &(*priv_0).hostlist);

                    if host_match == 1 as libc::c_int {
                        puts(b"\thost  matched\0" as *const u8 as *const libc::c_char);

                        cs = *(*((*priv_0).cmndlist.tqh_last as *mut cmndspec_list)).tqh_last;
                        while !cs.is_null() {
                            runas_match = runaslist_matches(
                                &mut parsed_policy,
                                (*cs).runasuserlist,
                                (*cs).runasgrouplist,
                                std::ptr::null_mut::<*mut member>(),
                                std::ptr::null_mut::<*mut member>(),
                            );
                            if runas_match == 1 as libc::c_int {
                                puts(b"\trunas matched\0" as *const u8 as *const libc::c_char);
                                cmnd_match = cmnd_matches(&mut parsed_policy, (*cs).cmnd);
                                if cmnd_match != -(1 as libc::c_int) {
                                    match_0 = cmnd_match;
                                }
                                printf(
                                    b"\tcmnd  %s\n\0" as *const u8 as *const libc::c_char,
                                    if match_0 == 1 as libc::c_int {
                                        b"allowed\0" as *const u8 as *const libc::c_char
                                    } else if match_0 == 0 as libc::c_int {
                                        b"denied\0" as *const u8 as *const libc::c_char
                                    } else {
                                        b"unmatched\0" as *const u8 as *const libc::c_char
                                    },
                                );
                            }
                            cs = *(*((*cs).entries.tqe_prev as *mut cmndspec_list)).tqh_last;
                        }
                    } else {
                        puts(b"\thost  unmatched\0" as *const u8 as *const libc::c_char);
                    }
                    priv_0 = *(*((*priv_0).entries.tqe_prev as *mut privilege_list)).tqh_last;
                }

                us = *(*((*us).entries.tqe_prev as *mut userspec_list)).tqh_last;
            } //while us..

            puts(if match_0 == 1 as libc::c_int {
                b"\nCommand allowed\0" as *const u8 as *const libc::c_char
            } else if match_0 == 0 as libc::c_int {
                b"\nCommand denied\0" as *const u8 as *const libc::c_char
            } else {
                b"\nCommand unmatched\0" as *const u8 as *const libc::c_char
            });

            exitcode = if parse_error as libc::c_int != 0 {
                1 as libc::c_int
            } else if match_0 == 1 as libc::c_int {
                0 as libc::c_int
            } else {
                match_0 + 3 as libc::c_int
            };
            break 'done;
        } //done: loop early

        sudo_lbuf_destroy_v1(&mut lbuf);
        sudo_freepwcache();
        sudo_freegrcache();
        sudo_debug_exit_int_v1(
            (*::std::mem::transmute::<&[u8; 5], &[libc::c_char; 5]>(b"main\0")).as_ptr(),
            b"testsudoers.c\0" as *const u8 as *const libc::c_char,
            380 as libc::c_int,
            sudo_debug_subsys,
            exitcode,
        );
        exit(exitcode);
    }
}

fn set_runaspw(mut user: *const libc::c_char) {
    let mut pw: *mut passwd = std::ptr::null_mut::<passwd>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());
    }

    unsafe {
        if *user as libc::c_int == '#' as i32 {
            let mut errstr: *const libc::c_char = std::ptr::null::<libc::c_char>();
            let mut uid: uid_t =
                sudo_strtoid_v2(user.offset(1 as libc::c_int as isize), &mut errstr);
            if errstr.is_null() {
                pw = sudo_getpwuid(uid);
                if pw.is_null() {
                    pw = sudo_fakepwnam(user, sudo_user.gid);
                }
            }
        }
        if pw.is_null() {
            pw = sudo_getpwnam(user);
            if pw.is_null() {
                sudo_fatalx!(
                    b"unknown user: %s\0" as *const u8 as *const libc::c_char,
                    user
                );
            }
        }
        if !(sudo_user._runas_pw).is_null() {
            sudo_pw_delref(sudo_user._runas_pw);
        }
        sudo_user._runas_pw = pw;

        debug_return!();
    }
}

fn set_runasgr(mut group: *const libc::c_char) {
    let mut gr: *mut group = std::ptr::null_mut::<group>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        if *group as libc::c_int == '#' as i32 {
            let mut errstr: *const libc::c_char = std::ptr::null::<libc::c_char>();
            let mut gid: gid_t =
                sudo_strtoid_v2(group.offset(1 as libc::c_int as isize), &mut errstr);
            if errstr.is_null() {
                gr = sudo_getgrgid(gid);
                if gr.is_null() {
                    gr = sudo_fakegrnam(group);
                }
            }
        }
        if gr.is_null() {
            gr = sudo_getgrnam(group);
            if gr.is_null() {
                sudo_fatalx!(
                    b"unknown group: %s\0" as *const u8 as *const libc::c_char,
                    group
                );
            }
        }
        if !(sudo_user._runas_gr).is_null() {
            sudo_gr_delref(sudo_user._runas_gr);
        }
        sudo_user._runas_gr = gr;

        debug_return!();
    } //unsafe
}

unsafe extern "C" fn cb_runas_default(mut sd_un: *const sudo_defs_val) -> bool {
    if runas_user.is_null() && runas_group.is_null() {
        set_runaspw((*sd_un).str_0);
    }
    1 as libc::c_int != 0
}

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn sudo_setspent() {}

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn sudo_endspent() {}

#[no_mangle]
pub fn open_sudoers(
    mut sudoers: *const libc::c_char,
    mut doedit: bool,
    mut keepopen: *mut bool,
) -> *mut FILE {
    let mut sb: stat = sb_all_arch;
    let mut fp: *mut FILE = std::ptr::null_mut::<FILE>();
    let mut sudoers_base: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        sudoers_base = strrchr(sudoers, '/' as i32);
        if !sudoers_base.is_null() {
            sudoers_base = sudoers_base.offset(1);
        }

        match sudo_secure_file_v1(sudoers, sudoers_uid, sudoers_gid, &mut sb) {
            SUDO_PATH_SECURE => {
                fp = fopen(sudoers, b"r\0" as *const u8 as *const libc::c_char);
            }
            SUDO_PATH_MISSING => {
                sudo_warn!(
                    b"unable to stat %s\0" as *const u8 as *const libc::c_char,
                    sudoers_base
                );
            }
            SUDO_PATH_BAD_TYPE => {
                sudo_warnx!(
                    b"%s is not a regular file\0" as *const u8 as *const libc::c_char,
                    sudoers_base
                );
            }
            SUDO_PATH_WRONG_OWNER => {
                sudo_warnx!(
                    b"%s should be owned by uid %u\0" as *const u8 as *const libc::c_char,
                    sudoers_base,
                    sudoers_uid
                );
            }
            SUDO_PATH_WORLD_WRITABLE => {
                sudo_warnx!(
                    b"%s is world writable\0" as *const u8 as *const libc::c_char,
                    sudoers_base
                );
            }
            SUDO_PATH_GROUP_WRITABLE => {
                sudo_warnx!(
                    b"%s should be owned by gid %u\0" as *const u8 as *const libc::c_char,
                    sudoers_base,
                    sudoers_uid
                );
            }
            _ => {}
        }

        debug_return_ptr!(fp);
    } //unsafe
}

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn init_envtables() -> bool {
    1 as libc::c_int != 0
}

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn set_perms(mut perm: libc::c_int) -> bool {
    1 as libc::c_int != 0
}

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn restore_perms() -> bool {
    1 as libc::c_int != 0
}

fn print_defaults(mut lbuf: *mut sudo_lbuf) -> bool {
    let mut def: *mut defaults_struct = std::ptr::null_mut::<defaults_struct>();
    let mut next: *mut defaults_struct = std::ptr::null_mut::<defaults_struct>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        def = parsed_policy.defaults.tqh_first;
        while !def.is_null() && {
            next = (*def).entries.tqe_next;
            1 as libc::c_int != 0
        } {
            sudoers_format_default_line(
                lbuf,
                &mut parsed_policy,
                def,
                &mut next,
                0 as libc::c_int != 0,
            );
            def = next;
        }
        debug_return_bool!(!sudo_lbuf_error_v1(lbuf));
    } //unsafe
}

unsafe extern "C" fn print_alias(
    mut parse_tree: *mut sudoers_parse_tree,
    mut a: *mut alias_struct,
    mut v: *mut libc::c_void,
) -> libc::c_int {
    let mut lbuf: *mut sudo_lbuf = v as *mut sudo_lbuf;
    let mut m: *mut member = std::ptr::null_mut::<member>();
    debug_decl!(SUDOERS_DEBUG_UTIL!());

    sudo_lbuf_append_v1(
        lbuf,
        b"%s %s = \0" as *const u8 as *const libc::c_char,
        alias_type_to_string((*a).type0 as libc::c_int),
        (*a).name,
    );
    m = (*a).members.tqh_first;
    while !m.is_null() {
        if m != (*a).members.tqh_first {
            sudo_lbuf_append_v1(lbuf, b", \0" as *const u8 as *const libc::c_char);
        }
        sudoers_format_member(
            lbuf,
            parse_tree,
            m,
            std::ptr::null::<libc::c_char>(),
            -(1 as libc::c_int),
        );
        m = (*m).entries.tqe_next;
    }
    sudo_lbuf_append_v1(lbuf, b"\n\0" as *const u8 as *const libc::c_char);

    debug_return_int!(if sudo_lbuf_error_v1(lbuf) as libc::c_int != 0 {
        -(1 as libc::c_int)
    } else {
        0 as libc::c_int
    });
}

unsafe extern "C" fn print_aliases(mut lbuf: *mut sudo_lbuf) -> bool {
    debug_decl!(SUDOERS_DEBUG_UTIL!());

    alias_apply(
        &mut parsed_policy,
        Some(
            print_alias
                as unsafe extern "C" fn(
                    *mut sudoers_parse_tree,
                    *mut alias_struct,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
        lbuf as *mut libc::c_void,
    );

    debug_return_bool!(!sudo_lbuf_error_v1(lbuf));
}

fn dump_sudoers(mut lbuf: *mut sudo_lbuf) {
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        'done: loop {
            if !print_defaults(lbuf) {
                break 'done;
            }
            if (*lbuf).len > 0 as libc::c_int {
                sudo_lbuf_print_v1(lbuf);
                sudo_lbuf_append_v1(lbuf, b"\n\0" as *const u8 as *const libc::c_char);
            }

            if !print_aliases(lbuf) {
                break 'done;
            }
            if (*lbuf).len > 1 as libc::c_int {
                sudo_lbuf_print_v1(lbuf);
                sudo_lbuf_append_v1(lbuf, b"\n\0" as *const u8 as *const libc::c_char);
            }

            if !sudoers_format_userspecs(
                lbuf,
                &mut parsed_policy,
                std::ptr::null::<libc::c_char>(),
                0 as libc::c_int != 0,
                1 as libc::c_int != 0,
            ) {
                break 'done;
            }

            if (*lbuf).len > 1 as libc::c_int {
                sudo_lbuf_print_v1(lbuf);
            }

            break 'done;
        } //end of done loop
          /*if sudo_lbuf_error_v1(lbuf) {
              if *__errno_location() == ENOMEM as libc::c_int {
                  sudo_fatalx!(
                      b"%s: %s\0" as *const u8 as *const libc::c_char,
                      get_function_name!(),
                      b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                  );
              }
          }*/
        if sudo_lbuf_error_v1(lbuf) && *__errno_location() == ENOMEM as libc::c_int {
            sudo_fatalx!(
                b"%s: %s\0" as *const u8 as *const libc::c_char,
                get_function_name!(),
                b"unable to allocate memory\0" as *const u8 as *const libc::c_char
            );
        }

        debug_return!();
    } //unsafe
} //end of fn

unsafe extern "C" fn testsudoers_output(mut buf: *const libc::c_char) -> libc::c_int {
    fputs(buf, stdout)
}

unsafe extern "C" fn testsudoers_error(mut buf: *const libc::c_char) -> libc::c_int {
    fputs(buf, stderr)
}

unsafe extern "C" fn usage() -> ! {
    fprintf(
        stderr,
        b"usage: %s [-dt] [-G sudoers_gid] [-g group] [-h host] [-i input_format] [-P grfile] [-p pwfile] [-U sudoers_uid] [-u user] <user> <command> [args]\n\0"
            as *const u8 as *const libc::c_char,
        sudo_getprogname(),
    );
    exit(1 as libc::c_int);
}

pub fn main() {
    let mut args: Vec<*mut libc::c_char> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::std::ptr::null_mut());

    ::std::process::exit(main_0((args.len() - 1) as libc::c_int, args.as_mut_ptr()) as i32)
}
